import wx
from Constant import *
from Basic_FallingObj import *
'''
GameObj_Stone :

    Game object of stone, it extends to Basic_FallingObj
'''
class GameObj_Stone(Basic_FallingObj):
    '''
    Constructor : GameObj_Stone
        mainMap - object pointer - MainMap
        pos - position of this object
    '''
    def __init__(self, mainMap, pos):
        Basic_FallingObj.__init__(self, mainMap, pos, GAME_OBJ_STONE)
        self._001_bindAction()
    '''
    function _001 : bind object event to specific method
    '''
    def _001_bindAction(self):
        self.mainMap.evtCollector.Bind(EVT_PUSH_STONE, self.SLOT001_pushStone)
    '''
    function SLOT001 : slot of the stone is push
    '''
    def SLOT001_pushStone(self, event):
        if (not self.isFalling) and self.mainMap.GET001_objTypeIn_listCube((self.posInMap[0] + 1, 
                                    self.posInMap[1])) != GAME_OBJ_STONE_WALL_TURNABLE:
            if event.targetPos[0] == self.posInMap[0] and event.targetPos[1] == self.posInMap[1] : #check target stone
                targetDir = event.dirVector
                #set position of master 
                if targetDir[1] == -1 :
                    imageIndex = ASP_LEFT
                else :
                    imageIndex = ASP_RIGHT
                masterCurPos = self.mainMap.obj_master.GET001_posInMap()
                masterNextPos = (masterCurPos[0] + targetDir[0], masterCurPos[1] + targetDir[1])
                self.mainMap.ACT003_changeObj(masterCurPos, GAME_OBJ_BLACK, 0)
                self.mainMap.ACT003_changeObj(masterNextPos, GAME_OBJ_MASTER, imageIndex)
                self.mainMap.obj_master.SET001_posInMap(masterNextPos)
                #move stone
                self.mainMap.ACT003_changeObj((self.posInMap[0] + targetDir[0], self.posInMap[1] + targetDir[1]),
                                              self.objType, 0)
                self.posInMap = (self.posInMap[0] + targetDir[0], self.posInMap[1] + targetDir[1])
                #add score
                wx.PostEvent(self.mainMap, NewEvt_addScore(AddScore = SCORE_PUSH_STONE))
        event.Skip()